home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Super Collection / Windows 95 Super Collection.iso / win95 / bench / thread / thrdoptn.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-13  |  6.9 KB  |  244 lines

  1. // thrdoptn.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "thrdomtr.h"
  6. #include "thrdoptn.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CThreadOptionsDlg dialog
  15.  
  16.  
  17. CThreadOptionsDlg::CThreadOptionsDlg(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CThreadOptionsDlg::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CThreadOptionsDlg)
  21.     m_nThreadCount = 0;
  22.     m_strLogFilename = _T("");
  23.     m_bLogOutput = FALSE;
  24.     m_bUseWindowPerThread = FALSE;
  25.     //}}AFX_DATA_INIT
  26.  
  27.     m_dwThreadPriorityClass = NORMAL_PRIORITY_CLASS; 
  28.     m_nTestType = 1;
  29.     m_bUseMutexObjects = TRUE;
  30. }
  31.  
  32.  
  33. void CThreadOptionsDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35.     CDialog::DoDataExchange(pDX);
  36.     //{{AFX_DATA_MAP(CThreadOptionsDlg)
  37.     DDX_Text(pDX, IDC_THREAD_COUNT, m_nThreadCount);
  38.     DDV_MinMaxInt(pDX, m_nThreadCount, 1, 64);
  39.     DDX_Text(pDX, IDC_LOG_FILENAME, m_strLogFilename);
  40.     DDV_MaxChars(pDX, m_strLogFilename, 255);
  41.     DDX_Check(pDX, IDC_LOG_OUTPUT_CHECK, m_bLogOutput);
  42.     DDX_Check(pDX, IDC_USE_WINDOW_PER_THREAD, m_bUseWindowPerThread);
  43.     //}}AFX_DATA_MAP
  44.  
  45.     // Do-it-ourselves data transfer.
  46.     if(pDX->m_bSaveAndValidate == FALSE)    
  47.     {
  48.         // Write member variables to controls.
  49.  
  50.         // Thread class.
  51.          if(m_dwThreadPriorityClass == IDLE_PRIORITY_CLASS)
  52.             CheckDlgButton(IDC_IDLE_TIME_THREADS, 1);
  53.         else if(m_dwThreadPriorityClass == HIGH_PRIORITY_CLASS)
  54.             CheckDlgButton(IDC_HIGH_PRIORITY_THREADS, 1);
  55.         else if(m_dwThreadPriorityClass == REALTIME_PRIORITY_CLASS)
  56.             CheckDlgButton(IDC_TIME_CRITICAL_THREADS, 1);
  57.         else // Default to 'normal' priority.
  58.             CheckDlgButton(IDC_NORMAL_PRIORITY_THREADS, 1);
  59.  
  60.         // Type of demo. to run.
  61.         if(m_nTestType == 1)
  62.         {
  63.             CheckDlgButton(IDC_PRIMES_DEMO, 1);                            
  64.         }
  65.         else if(m_nTestType == 2)
  66.         {
  67.             CheckDlgButton(IDC_FP_CALC_DEMO, 1);
  68.         }
  69.         else if(m_nTestType == 3)
  70.         {
  71.             CheckDlgButton(IDC_TIMED_GRAPHICS_DEMO, 1);
  72.             CheckDlgButton(IDC_USE_WINDOW_PER_THREAD, TRUE);
  73.             GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(FALSE);
  74.         }
  75.         else // I.e., m_nTestType == 4
  76.         {
  77.             CheckDlgButton(IDC_UNTIMED_GRAPHICS_DEMO, 1);
  78.             CheckDlgButton(IDC_USE_WINDOW_PER_THREAD, TRUE);
  79.             GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(FALSE);
  80.         }
  81.  
  82.         // Mutex or critical sections.
  83.         if(m_bUseMutexObjects)
  84.             CheckDlgButton(IDC_USE_MUTEX_OBJECTS, 1);
  85.         else
  86.             CheckDlgButton(IDC_USE_CRITICAL_SECTIONS, 1);                
  87.     }
  88.     else
  89.     {
  90.         // Save controls to member variables.
  91.         // Thread class.
  92.         if(IsDlgButtonChecked(IDC_IDLE_TIME_THREADS))
  93.             m_dwThreadPriorityClass = IDLE_PRIORITY_CLASS;
  94.         else if(IsDlgButtonChecked(IDC_HIGH_PRIORITY_THREADS))
  95.             m_dwThreadPriorityClass = HIGH_PRIORITY_CLASS;
  96.         else if(IsDlgButtonChecked(IDC_TIME_CRITICAL_THREADS))
  97.             m_dwThreadPriorityClass = REALTIME_PRIORITY_CLASS;
  98.         else // Default to 'normal' priority.
  99.             m_dwThreadPriorityClass = NORMAL_PRIORITY_CLASS;
  100.  
  101.         // Demo. test.
  102.         if(IsDlgButtonChecked(IDC_PRIMES_DEMO))                            
  103.             m_nTestType = 1;
  104.         else if(IsDlgButtonChecked(IDC_FP_CALC_DEMO))
  105.             m_nTestType = 2;
  106.         else if(IsDlgButtonChecked(IDC_TIMED_GRAPHICS_DEMO))
  107.             m_nTestType = 3;
  108.         else  // Then IDC_UNTIMED_GRAPHICS_DEMO.
  109.             m_nTestType = 4;            
  110.  
  111.         // Mutex or critical sections.
  112.         if(IsDlgButtonChecked(IDC_USE_MUTEX_OBJECTS))
  113.             m_bUseMutexObjects = TRUE;
  114.         else
  115.             m_bUseMutexObjects = FALSE;
  116.     }
  117. }
  118.  
  119.  
  120. BEGIN_MESSAGE_MAP(CThreadOptionsDlg, CDialog)
  121.     //{{AFX_MSG_MAP(CThreadOptionsDlg)
  122.     ON_BN_CLICKED(IDC_LOG_OUTPUT_CHECK, OnLogOutputCheck)
  123.     ON_BN_CLICKED(IDC_BROWSE_LOG_BTN, OnBrowseLogBtn)
  124.     ON_WM_VSCROLL()
  125.     ON_BN_CLICKED(IDC_TIMED_GRAPHICS_DEMO, OnTimedGraphicsDemo)
  126.     ON_BN_CLICKED(IDC_UNTIMED_GRAPHICS_DEMO, OnUntimedGraphicsDemo)
  127.     ON_BN_CLICKED(IDC_PRIMES_DEMO, OnPrimesDemo)
  128.     ON_BN_CLICKED(IDC_FP_CALC_DEMO, OnFpCalcDemo)
  129.     //}}AFX_MSG_MAP
  130. END_MESSAGE_MAP()
  131.  
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CThreadOptionsDlg message handlers
  135.  
  136. void CThreadOptionsDlg::OnLogOutputCheck() 
  137. {
  138.     // Enable or disable filename controls depending on whether
  139.     // log option is enabled.
  140.     int bEnabled = IsDlgButtonChecked(IDC_LOG_OUTPUT_CHECK);
  141.  
  142.     GetDlgItem(IDC_LOG_FILENAME)->EnableWindow(bEnabled);
  143.     GetDlgItem(IDC_BROWSE_LOG_BTN)->EnableWindow(bEnabled);
  144. }
  145.  
  146. BOOL CThreadOptionsDlg::OnInitDialog() 
  147. {
  148.     CDialog::OnInitDialog();
  149.  
  150.     if(IsDlgButtonChecked(IDC_LOG_OUTPUT_CHECK))
  151.     {
  152.         GetDlgItem(IDC_LOG_FILENAME)->EnableWindow(TRUE);
  153.         GetDlgItem(IDC_BROWSE_LOG_BTN)->EnableWindow(TRUE);
  154.     }
  155.     else
  156.     {
  157.         GetDlgItem(IDC_LOG_FILENAME)->EnableWindow(FALSE);
  158.         GetDlgItem(IDC_BROWSE_LOG_BTN)->EnableWindow(FALSE);
  159.     }
  160.         
  161.     return TRUE;  // return TRUE unless you set the focus to a control
  162.                   // EXCEPTION: OCX Property Pages should return FALSE
  163. }
  164.  
  165. void CThreadOptionsDlg::OnBrowseLogBtn() 
  166. {
  167.     // Allow user to set a filename.
  168.     CFileDialog BrowseFileDlg(FALSE, "*.txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Log files (*.txt)|*.txt|All files (*.*)|*.*||");
  169.     
  170.     CString strNewPath;
  171.  
  172.     BrowseFileDlg.m_ofn.lpstrTitle = "Save Log File As";
  173.  
  174.     int rc = BrowseFileDlg.DoModal();
  175.  
  176.     if(rc)
  177.     {
  178.         strNewPath = BrowseFileDlg.GetPathName();
  179.         GetDlgItem(IDC_LOG_FILENAME)->SetWindowText(strNewPath);
  180.     }
  181. }
  182.  
  183. void CThreadOptionsDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  184. {
  185.     // Do 'spin-button' functionality for # of threads edit control.
  186.     
  187.     // ***Note that MFC v. 3.2 provides a Windows 95 CSpinButtonCtrl to 
  188.     // do this for you.  (Using MFC 3.0 functionality for Visual C++ 2.0/2.1
  189.     // users.)
  190.     
  191.     if(pScrollBar->GetDlgCtrlID() == IDC_SPIN_THREAD_COUNT)
  192.     {
  193.         int nNewThreadCount = GetDlgItemInt(IDC_THREAD_COUNT);
  194.         
  195.         if(nSBCode == SB_LINEDOWN)
  196.             nNewThreadCount--;
  197.         else if(nSBCode == SB_LINEUP)
  198.             nNewThreadCount++;
  199.  
  200.         // Ensure range from 1 to 64.
  201.         nNewThreadCount = max(nNewThreadCount, 1);
  202.         nNewThreadCount = min(nNewThreadCount, 64);
  203.  
  204.         SetDlgItemInt(IDC_THREAD_COUNT, nNewThreadCount, FALSE);
  205.                 
  206.         CEdit *ThreadCountEdit = (CEdit *)GetDlgItem(IDC_THREAD_COUNT);
  207.         
  208.         // Highlight all chars. inside edit control.
  209.         ThreadCountEdit->SetSel(0, -1);
  210.                         
  211.         // Give it the focus as well.
  212.         ThreadCountEdit->SetFocus();
  213.     }
  214.     else
  215.         CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  216. }
  217.  
  218. void CThreadOptionsDlg::OnTimedGraphicsDemo() 
  219. {
  220.     // Must use window for this test.
  221.     CheckDlgButton(IDC_USE_WINDOW_PER_THREAD, TRUE);
  222.     GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(FALSE);
  223. }
  224.  
  225. void CThreadOptionsDlg::OnUntimedGraphicsDemo() 
  226. {
  227.     // Must use window for this test.
  228.     CheckDlgButton(IDC_USE_WINDOW_PER_THREAD, TRUE);
  229.     GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(FALSE);
  230. }
  231.  
  232.  
  233. void CThreadOptionsDlg::OnPrimesDemo() 
  234. {
  235.     // Window is optional for this test.
  236.     GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(TRUE);
  237. }
  238.  
  239. void CThreadOptionsDlg::OnFpCalcDemo() 
  240. {
  241.     // Window is optional for this test.
  242.     GetDlgItem(IDC_USE_WINDOW_PER_THREAD)->EnableWindow(TRUE);
  243. }
  244.